<?php
namespace app\admin\controller;

use think\Controller;
use think\Session;
use think\Db;

class Order extends Controller
{
    public function index() {
        $this->checkLogin();
        $arr = [];
        $arr = Db::table('ordertype')
        ->alias('o')
        ->join('activity a','o.activity_id = a.activity_id ')
        ->join('users u','o.user_id = u.user_id')
        ->select();
      
        for($i = 0;$i < count($arr);$i ++) {
            $arr[$i]['name'] = $arr[$i]['activity_name'];
            $arr[$i]['price'] = $arr[$i]['activity_price'];
        }

        $arr1 = [];
        $arr1 = Db::table('ordertype')
        ->alias('o')
        ->join('game g','o.game_id = g.game_id')
        ->join('users u','o.user_id = u.user_id')
        ->select();
        for($i = 0;$i < count($arr1);$i ++) {
             $arr1[$i]['name'] = $arr1[$i]['game_name'];
             $arr1[$i]['price'] = $arr1[$i]['game_price'];
        }

        $arr2=[];
        $arr2 = Db::table('ordertype')
        ->alias('o')
        ->join('train t','o.train_id = t.train_id')
        ->join('users u','o.user_id = u.user_id')
        ->select();
        for($i = 0;$i < count($arr2);$i ++) {
             $arr2[$i]['name'] = $arr2[$i]['train_name'];
             $arr2[$i]['price'] = $arr2[$i]['train_price'];
        }

        $result = array_merge($arr,$arr1,$arr2);
        $count = count($result);
        $this->assign('count', $count);
        $this->assign('list', $result);
        return $this->fetch();
       
    }

    public function delect () {
        $this->checkLogin();
        $request=input('ordertype_id');
        if (Db::table("ordertype")->delete($request)){
            $this->success("删除成功");
        }
        else{
            $this->error("删除失败");
        }
    }

    public function search () {
        $this->checkLogin();
        $content = input('content');
        $arr = [];
        $arr = Db::table('ordertype')
        ->alias('o')
        ->join('activity a','o.activity_id = a.activity_id ')
        ->join('users u','o.user_id = u.user_id')
        ->where('activity_name','like','%'.$content.'%')
        ->select();
      
        for($i = 0;$i < count($arr);$i ++) {
            $arr[$i]['name'] = $arr[$i]['activity_name'];
            $arr[$i]['price'] = $arr[$i]['activity_price'];
        }

        $arr1 = [];
        $arr1 = Db::table('ordertype')
        ->alias('o')
        ->join('game g','o.game_id = g.game_id')
        ->join('users u','o.user_id = u.user_id')
        ->where('game_name','like','%'.$content.'%')
        ->select();
        for($i = 0;$i < count($arr1);$i ++) {
             $arr1[$i]['name'] = $arr1[$i]['game_name'];
             $arr1[$i]['price'] = $arr1[$i]['game_price'];
        }

        $arr2=[];
        $arr2 = Db::table('ordertype')
        ->alias('o')
        ->join('train t','o.train_id = t.train_id')
        ->join('users u','o.user_id = u.user_id')
        ->where('train_name','like','%'.$content.'%')
        ->select();
        for($i = 0;$i < count($arr2);$i ++) {
             $arr2[$i]['name'] = $arr2[$i]['train_name'];
             $arr2[$i]['price'] = $arr2[$i]['train_price'];
        }

        $result = array_merge($arr,$arr1,$arr2);
        $count = count($result);
        $this->assign('count', $count);
        $this->assign('list', $result);
        return $this->fetch('index');
    }
}